/*
 * Copyright 2018 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.admin.utils;

import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

/**
 * <pre>
 * Shiro工具类
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018年3月7日 上午11:51:11
 * @since 1.0
 */
public abstract class ShiroUtils {

	public static final String PREMISSION_STRING = "perms[{0}]";

	/**
	 * <pre>
	 * 获取过滤器的资源，多地方调用，重构成工具类，免得修改时候修改的不全面
	 * </pre>
	 * 
	 * @param resourcesList
	 * @return
	 */
	public static Map<String, String> initMap(List<String> resourcesList) {
		Map<String, String> ocs = new LinkedHashMap<>();
		if (resourcesList != null) {
			for (String url : resourcesList) {
				if (StringUtils.isNotBlank(url)) {
					ocs.put(url, MessageFormat.format(PREMISSION_STRING, url));
				}
			}
		}

		ocs.put("/logout", "logout");
		ocs.put("/login", "anon");
		ocs.put("/static/**", "anon");
		ocs.put("/favicon.ico", "anon");
		ocs.put("/**", "authc");

		return ocs;
	}

}
